// 查询
//var Excute = require('./excute.js');
//var excute = new Excute(__dirname);

var baseJson = {
	"status": 1,
	"message": '',
	"value": ''
}

function getResult(result) {
	if ( result ) {
		baseJson.status = 1;
		baseJson.message = "获取成功";
		if(result.length === 1)
			baseJson.value = result[0];
		else
		baseJson.value = result;
	} else {
		baseJson.status = 0;
		baseJson.message = "获取失败";
		baseJson.value = "";
	}
}

function sqlQuery(sql) {
	if (arguments.length === 2) {
		sqlParam = [];
		res = arguments[1];
	} else {
		sqlParam = arguments[1];
		res = arguments[2];
	}
	excute.query(sql, sqlParam, function(result) {
		if (!result) {
			console.log(result);
		}
		res.setHeader('content-type', 'text/plain;charset=utf-8');
		getResult(result);
        res.end(JSON.stringify(baseJson));
//		debug && console.log(JSON.stringify(baseJson));
//		console.log( JSON.stringify(result) )
//      res.end(JSON.stringify(result));
		
	});
}


module.exports = sqlQuery;